<%--
 * (c)2010-2011 Andrea Caltroni (andrea.caltroni@pd.infn.it), INFN (www.infn.it)
 *
 * This file is part of the IGI Survey Portlet (from here on shortened to IGISP).
 * IGISP is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) any 
 * later version.
 *
 * IGISP is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IGISP. If not, see <http://www.gnu.org/licenses/>.
 *
--%>

<%@ include file="./init.jsp" %>

<% pageContext.setAttribute("newLineChar", "\n"); %>
<% pageContext.setAttribute("newLineHtml", "<br />"); %>

<c:set var="numAnswers" value="${fn:length(question.answers)}" />

<h3><spring:message code="answerOrderChange.view.title"/></h3>
<table class="lfr-table">
    <tr>
        <th><spring:message code="survey.label.question"/>:</th>
        <td>${question.description}</td>
    </tr>
</table>
<div class="lfr-separator">&nbsp;</div>

<div class="portlet-body">

    <portlet:actionURL var="actionUrl">
        <portlet:param name="action" value="changeAnswerOrder"/>
        <portlet:param name="questionID" value="${question.id}"/>
    </portlet:actionURL>

    <form:form name="changeAnswerOrderForm" commandName="changeAnswerOrderCommand" method="post" action="${actionUrl}">

    <div><form:errors cssClass="portlet-msg-error" /></div>

    <table class="lfr-table">
<c:choose><c:when test="${numAnswers <= 0}">
        <tr>
            <td colspan="3"><spring:message code="survey.label.noAnswers"/></td>
        </tr>
</c:when>
<c:otherwise>
        <tr>
            <th><spring:message code="answer.label.position"/></th>
            <th><spring:message code="answer.label.description"/></th>
            <th><spring:message code="answer.label.answerMode"/></th>
        </tr>
    <c:forEach var="answer" items="${changeAnswerOrderCommand.answers}" varStatus="loopStatus">
        <tr>
            <td><form:select path="answers[${loopStatus.index}].position" items="${answerPositions}" title="position"/> 
                <form:errors cssClass="portlet-msg-error" path="answers[${loopStatus.index}].position" />
            </td>
            <td><c:out value="${fn:replace(answer.description, newLineChar, newLineHtml)}" escapeXml="false" /></td>
            <td>${answer.answerMode.translatedName}</td>
        </tr>
    </c:forEach>
</c:otherwise></c:choose>
    </table>

        <div class="lfr-separator">&nbsp;</div>
    
        <div class="lfr-toolbar">
            <button type="submit"><spring:message code="button.save"/></button>
        </div>

    </form:form>

</div>

<div class="lfr-separator">&nbsp;</div>

<div class="lfr-toolbar">
    <!-- TODO survey is not in the model, right? -->
    <!-- <a href="<portlet:renderURL><portlet:param name="action" value="viewSurveyQuestions"/><portlet:param name="survey" value="${question.survey.id}"/></portlet:renderURL>"><img title="<spring:message code="surveyQuestions.view.button"/>" src="<html:imagesPath/>view-questions.png" border=0 /></a>&nbsp; -->
	<a href="<portlet:renderURL portletMode="view"/>"><img title="<spring:message code="button.home"/>" src="<html:imagesPath/>home.png" border=0 /></a>
</div>
